//
//  MNDBankCardViewController.m
//  minidai
//
//  Created by 容贤郁 on 2018/3/21.
//  Copyright © 2018年 迷你金服. All rights reserved.
//

#import "MNDBankCardViewController.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "NSString+BankCardFormatter.h"
#import "MNDDepositWebViewController.h"

@interface MNDBankCardViewController ()

@property (weak, nonatomic) IBOutlet UIView *shadowView;
@property (weak, nonatomic) IBOutlet UIImageView *bankLogo;
@property (weak, nonatomic) IBOutlet UILabel *bankNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *bankcardNumberLabel;

@property (weak, nonatomic) IBOutlet UIButton *unbindCardButton;

@end

@implementation MNDBankCardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.shadowView.layer.shadowOpacity = 0.4;
    self.shadowView.layer.shadowOffset = CGSizeMake(3.0, 3.0);
    self.shadowView.layer.shadowRadius = 8.0;
    self.shadowView.layer.shadowColor = kColorGray.CGColor;
    
    [self.bankLogo sd_setImageWithURL:[NSURL URLWithString:self.bankModel.jxBankaccount.bank.banklogo]
                     placeholderImage:[UIImage imageNamed:@"bank_logo_placeholder"]];
    
    self.bankNameLabel.text = self.bankModel.jxBankaccount.bank.bank;
    self.bankcardNumberLabel.text = [self.bankModel.jxBankaccount.userAmountCardno formatterBankCardNum];
    
    [self.unbindCardButton setHidden:self.hideUnbindButton];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)unbundingAction:(UIButton *)sender {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您将解绑当前银行卡" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"解绑" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self unbindBankCard];
    }];
    
    [alert addAction:cancelAction];
    [alert addAction:action];
    
    [self presentViewController:alert animated:YES completion:^{
        
    }];
}

#pragma mark - Network

- (void)unbindBankCard {
    WeakSelf(self);
    [NetworkProgressHUD showHud];
    
    [APIManager sendRequestWithPath:API_UNBIND_BANKCAR parameters:[MNDSign signedParamWithDict:@{@"channel": @"app"}] method:kXMHTTPMethodPOST onSuccess:^(ResponseModel *responseModel) {
        [NetworkProgressHUD hideHud];
        if (responseModel.status == ResponseSuccess) {
           
            MNDDepositWebViewController *webVC = [UIStoryboard viewControllerWithIdentifier:[MNDDepositWebViewController description]];
            webVC.htmlStr = responseModel.data;
            webVC.title = @"解绑银行卡";
            NSInteger index = [self.navigationController.childViewControllers indexOfObject:self];
            webVC.fromNaviIndex = index;
            [weakself.navigationController pushViewController:webVC animated:YES];

        } else {
            [NetworkProgressHUD showHudMsg:responseModel.msg[@"error"]];
        }
        
    } onFailure:^(NSError *error) {
        [NetworkProgressHUD showHudNetworkError:error];
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
